package com.teemor.im.executor;

import com.teemor.im.common.command.EventType;
import com.teemor.im.common.command.RemoteCommand;
import com.teemor.im.executor.handler.CommandHandler;
import com.teemor.im.remoting.netty.ResponseFuture;
import io.netty.channel.ChannelHandlerContext;
import lombok.Data;

/**
 * @ename zhoulk
 * @cname 周李科
 * @date 2020/6/17 14:30
 */
@Data
public class CommandTask implements Runnable {

    private EventType eventType;

    private ChannelHandlerContext ctx;

    private RemoteCommand command;

    private CommandHandler handler;

    private ResponseFuture responseFuture;

    private CommandCallback callback;

    public CommandTask(RemoteCommand command, EventType eventType, ResponseFuture responseFuture) {
        this.command = command;
        this.eventType = eventType;
        this.responseFuture = responseFuture;
    }


    @Override
    public void run() {
        RemoteCommand remoteCommand = null;
        if (handler != null)
            remoteCommand = handler.run(CommandTask.this);
        if (callback != null)
            callback.callback(remoteCommand);
    }
}
